package logic

import (
	"context"
	"rent-ease/models/mysql"

	"rent-ease/rentrpc/internal/svc"
	"rent-ease/rentrpc/rentrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DetailLogic) Detail(in *rentrpc.DetailRequest) (*rentrpc.DetailResponse, error) {
	// todo: add your logic here and delete this line

	var rent mysql.Rent
	err := rent.DetailRent(mysql.DB, in.RentId)
	if err != nil {
		return nil, err
	}

	return &rentrpc.DetailResponse{
		RentName: rent.RentName,
		Address:  rent.Address,
		RentId:   int64(rent.ID),
	}, nil
}
